# DjangoDE, an integrated development environment for Django
# Copyright (C) 2010-2011 Andrew Wilkinson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

from djangode import global_objects
from djangode.utils.qt import QtCore, QtGui

class ProjectSettingsDialog(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)

        self.setWindowTitle("Project Settings")
        self.setWindowIcon(QtGui.QIcon(global_objects.icon))

        layout = QtGui.QGridLayout(self)

        layout.addWidget(QtGui.QLabel("Pre-runserver command"), 0, 0)

        self.pre_runserver_command = QtGui.QLineEdit(global_objects.project.settings.get("pre_runserver_command", ""))
        layout.addWidget(self.pre_runserver_command, 0, 1)

        self.close_button = QtGui.QPushButton("Close")
        self.close_button.setDefault(True)
        self.close_button.clicked.connect(self.close)
        layout.addWidget(self.close_button, 1, 1, QtCore.Qt.AlignRight)

    def closeEvent(self, event):
        global_objects.project.settings["pre_runserver_command"] = self.pre_runserver_command.text()

        if global_objects.project.settings.dirty:
            global_objects.project.runner.stop()
            global_objects.project.runner.start()

        return QtGui.QDialog.closeEvent(self, event)
